package com.example.mvptest.present;

import com.example.mvptest.model.CalcModel;
import com.example.mvptest.view.CalcView;

public class CalcPresent implements OnCalcListener {
	
	private CalcView calcView;
	private CalcModel calcModel;
	
	public CalcPresent(CalcView calcView) {
		this.calcView = calcView;
		this.calcModel = new CalcModel(this);
	}
	
	
	public void submit() {
		if (calcView == null) {
			return;
		}
		String firstNum = calcView.getFirstNum();
		String secondNum = calcView.getSecondNum();
		
		try {
			calcModel.calc(Double.parseDouble(firstNum), Double.parseDouble(secondNum));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	

	@Override
	public void showResult(double result) {
		calcView.setResultText(result);
	}
	
}
